<%@ page pageEncoding="UTF-8"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%@include file="../../tld.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>新增收货地址</title>
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport" />
    <meta content="yes" name="apple-mobile-web-app-capable" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=no" name="format-detection" />
    <!-- 引入公用样式 -->
    <link rel="stylesheet" href="../../../static/sass/common/ydui.css" />
    <link rel="stylesheet" href="../../../static/stylesheets/user/address.css" />
    <!-- 引入自适应解决方案类库 -->
    <script src="../../../static/scripts/libs/ydui.flexible.js"></script>
</head>
<body>
    <div class="g-flexview">
        <!-- 主体内容开始 -->
        <form:form id="myFormId" commandName="modle" modelAttribute="model" action="${pageContext.request.contextPath}/address/saveorupdate" onsubmit="return checkForm();" method="post">
        <input type="hidden" value="${uid }" name="userId">
        <input type="hidden" value="${model.id}" name="id">
        <input type="hidden" id="url" name="url">
        <section class="content_box">
            <div class="m-cell">
                <div class="cell-item">
                    <div class="cell-left">姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名</div>
                    <div class="cell-right"><input type="text" placeholder="请输入姓名" value="${model.receiveName }" name="receiveName" class="cell-input"  autocomplete="off" /></div>
                </div>
                <div class="cell-item">
                    <div class="cell-left">联系电话</div>
                    <div class="cell-right"><input type="text" placeholder="请输入联系电话" value="${model.receiverMobile }" name="receiverMobile" class="cell-input" autocomplete="off" /></div>
                </div>
                <div class="cell-item">
                    <div class="cell-left">收货地址</div>
                    <div class="cell-right cell-arrow">
                        <input type="text" value="${model.preAddress}" name="preAddress" class="cell-input" readonly id="J_Address2" value="" placeholder="请选择收货地址">
                    </div>
                </div>
                <div class="cell-item">
                    <div class="cell-left">详细地址</div>
                    <div class="cell-right"><input type="text" value="${model.receiverAddress}" name="receiverAddress" placeholder="请输入详细地址" class="cell-input" autocomplete="off" /></div>
                </div>
                <div class="cell-item">
                    <div class="cell-left">邮政编码</div>
                    <div class="cell-right"><input type="text" placeholder="(选填)" value="${model.receiverZip}" name="receiverZip" class="cell-input" autocomplete="off" /></div>
                </div>
            </div>
        </section>
        <button type="submit" class="btn-block btn-primary" style="position: fixed; bottom: 0; left: 0; background: #3f9a31;">保存</button>
        </form:form>
    </div>
    <!-- 引入jQuery 2.0+ -->
    <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <!-- 引入YDUI脚本 -->
    <script src="../../../static/scripts/libs/ydui.citys.js"></script>
    <script src="../../../static/scripts/libs/ydui.js"></script>
    <script>
        /**
        * 设置默认值
        */
        !function () {
           var $target = $('#J_Address2');

           $target.on('click', function (event) {
               event.stopPropagation();
               $target.citySelect('open');
           });

           $target.on('done.ydui.cityselect', function (ret) {
               $(this).val(ret.provance + ' ' + ret.city + ' ' + ret.area);
           });
        }();
        function getUrlParam(name){
    	    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    	    var r = window.location.search.substr(1).match(reg);
    	    if (r!=null) return unescape(r[2]); return null;
    	}
    	var backFlag = getUrlParam('backFlag');
        function checkForm(){
      		var receiveName=$("[name='receiveName']").val();
      		var receiverMobile=$("[name='receiverMobile']").val();
      		var preAddress=$("[name='preAddress']").val();
      		var receiverAddress=$("[name='receiverAddress']").val();
      		var receiverZip=$("[name='receiverZip']").val();
      		var url="";
      		var action = $("#myFormId").attr("action");
      		if(null != backFlag && backFlag == 1){
      			var goodsId = getUrlParam('goodsId');
      			var buyType = getUrlParam('buyType');
      			var buyNum = getUrlParam('buyNum');
      			url = 'goodsId='+goodsId+'&buyType='+buyType+'&buyNum='+buyNum+'&userId='+uid+'&backFlag=1';
      			$("#url").val(url);
      			$("#myFormId").attr("action",action+"?"+url);
      		}
      		if(null != backFlag && backFlag == 2){
      			var cartIds = getUrlParam('cartIds');
      			url = 'cartIds='+cartIds+'&userId='+uid+'&backFlag=2';
      			alert(url)
      			$("#url").val(url);
      			$("#myFormId").attr("action",action+"?"+url);
      		}
      		if(null == receiveName || '' == receiveName){
      			alert("请填写姓名");
      			return false;
      		}
      		if(null == receiverMobile || '' == receiverMobile){
      			alert("请填写电话");
      			return false;
      		}
      		if(null == preAddress || '' == preAddress){
      			alert("请填写省市区");
      			return false;
      		}
      		if(null == receiverAddress || '' == receiverAddress){
      			alert("请填写详细地址");
      			return false;
      		}
      		if(null == receiverZip || '' == receiverZip){
      			alert("请填写邮编");
      			return false;
      		}
        	return true;
        }
    </script>
</body>

</html>
